home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Vertigo / Loader / Loader.c next >
Encoding:
C/C++ Source or Header  |  2000-06-24  |  1.4 KB  |  85 lines

  1. #define DISABLE_LOCAL_CALLTRACE        1        // Set to 1 to disable Call Traces for this file.
  2. #define DISABLE_LOCAL_DEBUG            0        // Set to 1 to disable all debugging for this file.
  3. #include "DebugUtils.h"
  4.  
  5. #include <Events.h>
  6. #include <Resources.h>
  7. #include "ContextUtils.h"
  8. #include "Nub.h"
  9.  
  10.  
  11.  
  12.  
  13.  
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17.  
  18. OSStatus main(void);
  19. static Boolean isPressed(UInt8 keyCode);
  20.  
  21. #ifdef __cplusplus
  22. }
  23. #endif
  24.  
  25.  
  26. #define CONTROL_KEY        0x3B
  27. #define OPTION_KEY        0x3A
  28. #define D_KEY            0x02
  29. #define S_KEY            0x01
  30.  
  31.  
  32.  
  33.  
  34.  
  35. OSStatus main(void)
  36. {
  37.     GlobalContext    globals;
  38.     THzContext        zone(SystemZone());
  39.     Handle            code;
  40.     OSStatus        err;
  41.     
  42.     
  43.     // Check and break.
  44.     #if DEBUG
  45.         if (isPressed(CONTROL_KEY) && isPressed(OPTION_KEY) && isPressed(D_KEY) && isPressed(S_KEY))
  46.             DebugStr("\pNub> Thank you for holding down CONTROL-OPTION-D-S");
  47.     #endif
  48.     
  49.     // Load the nub code resource.
  50.     code = Get1Resource('nub ',0);
  51.     if (code == NULL)
  52.     {
  53.         dprintf(kDConPrefix "Get1Resource('nub ',0) failed: %ld\n",ResError());
  54.         return -1;
  55.     }
  56.     
  57.     // Detach and lock code resource
  58.     // so we can safely call it.
  59.     DetachResource(code);
  60.     HLock(code);
  61.     
  62.     // Call the main entry point.
  63.     err = CallNubLoadProc((NubLoadUPP)(*code),code);
  64.     if (err != noErr)
  65.     {
  66.         dprintf(kDConPrefix "NubLoad failed: %ld  %s:%d\n",err);
  67.         DisposeHandle(code);
  68.     }
  69.     
  70.     return err;
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
  77. Boolean isPressed(UInt8 keyCode)
  78. {
  79.     UInt8    km[16];
  80.     
  81.     
  82.     GetKeys((UInt32*)&km[0]);
  83.     return ((km[keyCode >> 3] >> (keyCode & 7)) & 1);
  84. }
  85.